class Solution(object):
    def missingNumber(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        n = len(nums)
        for i in range(n):
            j = i
            next_j = nums[j]
            while j != next_j and next_j < n:
                new_next = nums[next_j]
                nums[next_j] = next_j
                j = next_j
                next_j = new_next
        for i in range(n):
            if nums[i] != i:
                return i
        return n


data = Solution()
nums = [9, 6, 4, 2, 3, 5, 7, 0, 1]
print(data.missingNumber(nums))
nums = [3, 0, 1]
print(data.missingNumber(nums))